package com.winit.projectPlan.repository;

import com.winit.projectPlan.model.Task;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface TaskRepository extends CrudRepository<Task, String>{
    @Query(value = "SELECT * FROM matrix_task WHERE (1=1) AND (?1 IS NULL  OR id = ?1) AND (?2 IS NULL OR number = ?2) AND (?3 IS NULL OR type = ?3) AND (?4 IS NULL OR charger_account = ?4) AND (?5 IS NULL OR status = ?5) AND (?6 IS NULL OR project_plan_id = ?6)", nativeQuery = true)
    List<Task> getTasks(String id, String number, String type, String chargerAccount, String status, String projectPlanId);
    @Transactional
    @Modifying
    @Query(value = "DELETE FROM matrix_task WHERE (1=1) AND (?1 IS NULL OR id = ?1) AND (?2 IS NULL OR number = ?2)", nativeQuery = true)
    int deleteByIdAndNumber(String id, String number);

//
//    @Query(value = "SELECT charger_account, charger_realname, count(1) AS num, status, SUM(work_hours) AS totalHour  FROM matrix_project_plan_task WHERE (1=1) AND (?1 IS NULL  OR project_plan_id = ?1) GROUP BY charger_account, status", nativeQuery = true)
//    List<ProjectPlanTaskMemberStats> getTaskMemberStats(String projectPlanId);
}
